﻿
Imports storoomc

Public Class perceptron
    Inherits Global.perceptron

    Private Class storoomServerDef
        Public host As String
        Public port As Int32
        Public retrytimes As Int64
    End Class

    Private storoomServer As storoomServerDef = Nothing

    Private Function getstoroom(ByRef host As String, ByRef port As Int32, ByRef retrytimes As Int64) As Boolean
        copy(host, storoomServer.host)
        port = storoomServer.port
        retrytimes = storoomServer.retrytimes
    End Function

    Public Overrides Sub initial(Optional ByVal config As configParser = Nothing)
        assert(Not config Is Nothing, "tagit.perceptron needs to be initialized with a valid config.")

        storoomServer.host = config.parameter(configNaming.storoom.name, configNaming.storoom.perceptronHost, _
                                              configNaming.defaultValue.storoom.perceptronHost)
        storoomServer.port = config.parameter(configNaming.storoom.name, configNaming.storoom.perceptronPort, _
                                              configNaming.defaultValue.storoom.perceptronPort)
        storoomServer.retrytimes = config.parameter(configNaming.storoom.name, _
                                                    configNaming.storoom.perceptronRetrytimes, _
                                                    configNaming.defaultValue.storoom.perceptronRetrytimes)
        storoom.initial(AddressOf getstoroom)
    End Sub

    Protected Overrides Function read(ByVal key As String, ByRef count As Long) As Boolean
        Return storoomReader.read(key, count)
    End Function

    Protected Overrides Function write(ByVal key As String, ByVal count As Long) As Boolean
        Return storoomModifier.modify(key, count)
    End Function

    Public Sub New()
        storoomServer = New storoomServerDef()
    End Sub
End Class
